cmake_minimum_required(VERSION 3.19)

project(chainsaw VERSION 1.1.1 LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "Install path" FORCE)
endif()

#
set(INSTALL_INCLUDE_DIR include)
set(INSTALL_LIB_DIR lib)
set(INSTALL_BIN_DIR bin)
set(GENERATE_DIR ${CMAKE_BINARY_DIR}/generate)

#
function(install_target_and_headers target module)
    install(TARGETS ${target}
            ARCHIVE DESTINATION ${INSTALL_LIB_DIR}   # share
            LIBRARY DESTINATION ${INSTALL_LIB_DIR}   # static
            RUNTIME DESTINATION ${INSTALL_BIN_DIR})  # runtime

    install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/${module}/include/
            DESTINATION ${INSTALL_INCLUDE_DIR}/${module}
            FILES_MATCHING 
            PATTERN "*.h"
            PATTERN "*.hpp"
            PATTERN "cmake" EXCLUDE)
endfunction()

add_subdirectory(src)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test")
    enable_testing()
    add_subdirectory(test)
ENDIF()
